package com.atguigu.algorithm;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class PrintAllSub2 {
        public static void function(String str){
            Set<String> set=new HashSet<>();
            char[] chars=str.toCharArray();
            process(chars,0,new ArrayList<>(),set);
            System.out.println(set.size());
        }
        public static void process(char[] chars, int i, List<Character> list,Set<String> set){
            if(i==chars.length){
                set.add(print(list));
                return;
            }else{
                List<Character> resKeep=copyList(list);
                resKeep.add(chars[i]);
                process(chars,i+1,resKeep,set); //要当前字符的路
                List<Character> resNoInclude=copyList(list);
                process(chars,i+1,resNoInclude,set); //不要当前字符的路
            }
        }

        public static void main(String[] args) {
            function("abc");
        }
        public static String print(List<Character> list){
            StringBuilder sb=new StringBuilder();
            while(!list.isEmpty()){
                sb.append(list.remove(0));
            }
            return sb.toString();
        }
        public static List<Character> copyList(List<Character> list){
            ArrayList<Character> res=new ArrayList<>();
            for(int i=0;i<list.size();i++){
                res.add(list.get(i));
            }
            return res;
        }
}
